package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayBookVocDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayChapterDTO;
import com.cskaoyan.wordmemorize.request.AppVocPageRequest;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.service.VocService;
import org.ehcache.shadow.org.terracotta.offheapstore.paging.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.cskaoyan.wordmemorize.auth.StpKit.USER;

@RestController
public class VocAppController {
    @Autowired
    VocService vocService;

    @GetMapping("/user/voc/detail/{vocId}")
    public Result<VocDTO> getVocDetail(@PathVariable("vocId") Long vocId) {
        long userId = Long.parseLong((String) USER.getLoginId());
        VocDTO vocDetail = vocService.getVocDetail(vocId, userId);
        return Result.ok(vocDetail);
    }

    @GetMapping("/user/voc/book/display")
    public Result getDisplayBookVocSInfo(AppVocPageRequest pageRequest) {
        long userId = Long.parseLong((String) USER.getLoginId());
        pageRequest.setUserId(String.valueOf(userId));
        PageDTO<DisplayBookVocDTO> displayBookVocSInfo = vocService.getDisplayBookVocsInfo(pageRequest);
        return Result.ok(displayBookVocSInfo);
    }

    @GetMapping("/user/voc/book/chapter/display")
    public Result getUserChooseCountInBook(AppVocPageRequest pageRequest) {
        long userId = Long.parseLong((String) USER.getLoginId());
        pageRequest.setUserId(String.valueOf(userId));
        PageDTO<DisplayChapterDTO> displayBookChapterVocSInfo = vocService.getDisplayBookChapterVocsInfo(pageRequest);
        return Result.ok(displayBookChapterVocSInfo);
    }
}
